//
// Created by 吴锐 on 2022/2/24.
//

#include "iostream"

using namespace std;

class Person {
public:
    int m_Age;
    int* m_Height;

    Person(){
        cout << "无参构造" << endl;
    }

    Person(int age, int height){
        m_Age = age;
        m_Height = new int(height);
        cout << "有参构造" << endl;
    }

    Person(const Person& p){
        cout << "拷贝构造的调用" << endl;
        m_Age = p.m_Age;
//        m_Height = p.m_Height;
        m_Height = new int(*p.m_Height);
    }

    ~Person(){
        if(m_Height != NULL){
            delete m_Height;
            m_Height = NULL;
        }
        cout << "析构函数" << endl;
    }
};

void test01(){
    Person p1(18, 160);
    cout << "p1的年龄为: " << p1.m_Age << "身高为: " << *p1.m_Height << endl;

    Person p2(p1);
    cout << "p1的年龄为: " << p2.m_Age << "身高为: " << *p2.m_Height << endl;
}

int main(){
    test01();
    return 0;
}